package com.member.web.controller.shop;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.member.common.annotation.Log;
import com.member.common.core.controller.BaseController;
import com.member.common.core.domain.AjaxResult;
import com.member.common.core.page.TableDataInfo;
import com.member.common.enums.BusinessType;
import com.member.common.utils.poi.ExcelUtil;
import com.member.shop.domain.SysBizActivity;
import com.member.shop.domain.SysBizActivityDealer;
import com.member.shop.service.ISysBizActivityDealerService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 【参与活动店铺】控制器
 *
 * @author lixinchen
 * @version 1.0
 * @date 2024-11-09
 **/
@RestController
@RequestMapping("/shop/activityDealer")
public class SysBizActivityDealerController extends BaseController {
    @Resource
    private ISysBizActivityDealerService sysBizActivityDealerService;

    private void setTenantId(SysBizActivityDealer sysBizActivityDealer) {
        Long tenantId = getTenantId();
        if (tenantId != null && tenantId > 0) {
            sysBizActivityDealer.setTenantId(tenantId);
        }
    }

    /**
     * 查询参与活动店铺列表
     */
    @PreAuthorize("@ss.hasPermi('shop:activityDealer:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysBizActivityDealer sysBizActivityDealer) {
        startPage();
        setTenantId(sysBizActivityDealer);
        List<SysBizActivityDealer> list = sysBizActivityDealerService.selectSysBizActivityDealerList(sysBizActivityDealer);
        return getDataTable(list);
    }

    /**
     * 导出参与活动店铺列表
     */
    @PreAuthorize("@ss.hasPermi('shop:activityDealer:export')")
    @Log(title = "参与活动店铺", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysBizActivityDealer sysBizActivityDealer) {
        setTenantId(sysBizActivityDealer);
        List<SysBizActivityDealer> list = sysBizActivityDealerService.selectSysBizActivityDealerList(sysBizActivityDealer);
        ExcelUtil<SysBizActivityDealer> util = new ExcelUtil<SysBizActivityDealer>(SysBizActivityDealer.class);
        util.exportExcel(response, list, "参与活动店铺数据");
    }

    /**
     * 获取参与活动店铺详细信息
     */
    @PreAuthorize("@ss.hasPermi('shop:activityDealer:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(sysBizActivityDealerService.selectSysBizActivityDealerById(id));
    }

    /**
     * 新增参与活动店铺
     */
    @PreAuthorize("@ss.hasPermi('shop:activityDealer:add')")
    @Log(title = "参与活动店铺", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysBizActivityDealer sysBizActivityDealer) {
        return toAjax(sysBizActivityDealerService.insertSysBizActivityDealer(sysBizActivityDealer));
    }

    /**
     * 修改参与活动店铺
     */
    @PreAuthorize("@ss.hasPermi('shop:activityDealer:edit')")
    @Log(title = "参与活动店铺", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysBizActivityDealer sysBizActivityDealer) {
        return toAjax(sysBizActivityDealerService.updateSysBizActivityDealer(sysBizActivityDealer));
    }

    /**
     * 删除参与活动店铺
     */
    @PreAuthorize("@ss.hasPermi('shop:activityDealer:remove')")
    @Log(title = "参与活动店铺", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(sysBizActivityDealerService.deleteSysBizActivityDealerByIds(ids));
    }
}
